home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / io / OutputStream.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  5.3 KB  |  139 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)OutputStream.java    1.21 98/04/09
  3.  *
  4.  * Copyright 1994-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17. /**
  18.  * This abstract class is the superclass of all classes representing 
  19.  * an output stream of bytes. An output stream accepts output bytes 
  20.  * and sends them to some sink.
  21.  * <p>
  22.  * Applications that need to define a subclass of 
  23.  * <code>OutputStream</code> must always provide at least a method 
  24.  * that writes one byte of output. 
  25.  *
  26.  * @author  Arthur van Hoff
  27.  * @version 1.21, 04/09/98
  28.  * @see     java.io.BufferedOutputStream
  29.  * @see     java.io.ByteArrayOutputStream
  30.  * @see     java.io.DataOutputStream
  31.  * @see     java.io.FilterOutputStream
  32.  * @see     java.io.InputStream
  33.  * @see     java.io.OutputStream#write(int)
  34.  * @since   JDK1.0
  35.  */
  36. public abstract class OutputStream {
  37.     /**
  38.      * Writes the specified byte to this output stream. The general 
  39.      * contract for <code>write</code> is that one byte is written 
  40.      * to the output stream. The byte to be written is the eight 
  41.      * low-order bits of the argument <code>b</code>. The 24 
  42.      * high-order bits of <code>b</code> are ignored.
  43.      * <p>
  44.      * Subclasses of <code>OutputStream</code> must provide an 
  45.      * implementation for this method. 
  46.      *
  47.      * @param      b   the <code>byte</code>.
  48.      * @exception  IOException  if an I/O error occurs. In particular, 
  49.      *             an <code>IOException</code> may be thrown if the 
  50.      *             output stream has been closed.
  51.      */
  52.     public abstract void write(int b) throws IOException;
  53.  
  54.     /**
  55.      * Writes <code>b.length</code> bytes from the specified byte array 
  56.      * to this output stream. The general contract for <code>write(b)</code> 
  57.      * is that it should have exactly the same effect as the call 
  58.      * <code>write(b, 0, b.length)</code>.
  59.      *
  60.      * @param      b   the data.
  61.      * @exception  IOException  if an I/O error occurs.
  62.      * @see        java.io.OutputStream#write(byte[], int, int)
  63.      */
  64.     public void write(byte b[]) throws IOException {
  65.     write(b, 0, b.length);
  66.     }
  67.  
  68.     /**
  69.      * Writes <code>len</code> bytes from the specified byte array 
  70.      * starting at offset <code>off</code> to this output stream. 
  71.      * The general contract for <code>write(b, off, len)</code> is that 
  72.      * some of the bytes in the array <code>b</code> are written to the 
  73.      * output stream in order; element <code>b[off]</code> is the first 
  74.      * byte written and <code>b[off+len-1]</code> is the last byte written 
  75.      * by this operation.
  76.      * <p>
  77.      * The <code>write</code> method of <code>OutputStream</code> calls 
  78.      * the write method of one argument on each of the bytes to be 
  79.      * written out. Subclasses are encouraged to override this method and 
  80.      * provide a more efficient implementation. 
  81.      * <p>
  82.      * If <code>b</code> is <code>null</code>, a 
  83.      * <code>NullPointerException</code> is thrown.
  84.      * <p>
  85.      * If <code>off</code> is negative, or <code>len</code> is negative, or 
  86.      * <code>off+len</code> is greater than the length of the array 
  87.      * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
  88.      *
  89.      * @param      b     the data.
  90.      * @param      off   the start offset in the data.
  91.      * @param      len   the number of bytes to write.
  92.      * @exception  IOException  if an I/O error occurs. In particular, 
  93.      *             an <code>IOException</code> is thrown if the output 
  94.      *             stream is closed.
  95.      */
  96.     public void write(byte b[], int off, int len) throws IOException {
  97.     if (b == null) {
  98.         throw new NullPointerException();
  99.     } else if ((off < 0) || (off > b.length) || (len < 0) ||
  100.            ((off + len) > b.length) || ((off + len) < 0)) {
  101.         throw new IndexOutOfBoundsException();
  102.     } else if (len == 0) {
  103.         return;
  104.     }
  105.     for (int i = 0 ; i < len ; i++) {
  106.         write(b[off + i]);
  107.     }
  108.     }
  109.  
  110.     /**
  111.      * Flushes this output stream and forces any buffered output bytes 
  112.      * to be written out. The general contract of <code>flush</code> is 
  113.      * that calling it is an indication that, if any bytes previously 
  114.      * written have been buffered by the implementation of the output 
  115.      * stream, such bytes should immediately be written to their 
  116.      * intended destination.
  117.      * <p>
  118.      * The <code>flush</code> method of <code>OutputStream</code> does nothing.
  119.      *
  120.      * @exception  IOException  if an I/O error occurs.
  121.      */
  122.     public void flush() throws IOException {
  123.     }
  124.  
  125.     /**
  126.      * Closes this output stream and releases any system resources 
  127.      * associated with this stream. The general contract of <code>close</code> 
  128.      * is that it closes the output stream. A closed stream cannot perform 
  129.      * output operations and cannot be reopened.
  130.      * <p>
  131.      * The <code>close</code> method of <code>OutputStream</code> does nothing.
  132.      *
  133.      * @exception  IOException  if an I/O error occurs.
  134.      */
  135.     public void close() throws IOException {
  136.     }
  137.  
  138. }
  139.